<template>
	<view class="home" v-if="isLogin">
		<view class="banner">
			<image src="http://klwl-file.oss-cn-shenzhen.aliyuncs.com/202105/jhstest/49642875526530.png" mode="widthFix"></image>
			<view class="banner-title">
				<image class="av-img" :src="vuex_adminuser.logo || '../static/logo.png'" mode=""></image>
				<view class="tit">
					<text class="pb-20">{{ vuex_adminuser.contact }}</text>
					<text>{{ vuex_adminuser.phone }}</text>
				</view>
			</view>
			<view class="setting" @click="open"><u-icon name="setting" color="#fff" size="40"></u-icon></view>
		</view>
		<view class="transaction">
			<view class="transaction-title">实时交易</view>
			<view class="echart">
				<div class="progress_box">
					<cmd-progress
						type="dashboard"
						:percent="percentage"
						stroke-color="#307aff"
						gap-degree="150"
						:stroke-width="6"
						:width="210"
						stroke-shape="round"
						:showInfo="false"
					></cmd-progress>
					<div class="xian_box" :style="{ 'background-image': 'url(http://klwl-file.oss-cn-shenzhen.aliyuncs.com/202105/jhstest/54098876544126.png)' }"></div>
					<view class="echart-title">
						<view class="title-top mb-4 fw-bold u-font-38">{{ $price(analysis.sum_money) }}</view>
						<view class="u-font-24">订单总金额(元）</view>
					</view>
				</div>
			</view>
			<view class="num_box num-left">
				<text class="u-font-48 fw-bold">{{ analysis.order_count }}</text>
				<text class="u-font-24">今日累计(件)</text>
			</view>
			<view class="num_box num-right">
				<text class="u-font-48 fw-bold">{{ analysis.order_money }}</text>
				<text class="u-font-24">今日交易额(元)</text>
			</view>
		</view>
		<view class="nav">
			<view class="nav-item" v-for="(item, index) in navList" :key="index" @click="openItem(item.url, index)">
				<view class="img"><view class="iconfont u-font-46" :class="item.icon"></view></view>
				<view class="">{{ item.name }}</view>
			</view>
			<view class="nav-item" v-for="(item, index) in navList.length % 4 == 0 ? 0 : 4 - (navList.length % 4)" :key="index">
				<view class="img" style="background-color: #fff;"><u-icon name="" size="30"></u-icon></view>
				<view class=""></view>
			</view>
		</view>
	</view>
</template>

<script>
import cmdProgress from '../components/cmd-progress/cmd-progress.vue';
import { adminPost } from '@/common/http.request.js';
import { mapState } from 'vuex';
import { wxScanCode } from '@/utils/uniPromise.js';
import queryParams from "@/utils/queryParams";
export default {
	components: {
		cmdProgress
	},
	data() {
		return {
			analysis: {},
			isLogin: false,
			navObj: {
				BProductTicket: {
					icon: 'iconfont-e60d',
					name: '售票',
					url: '/package/system/ticket/index'
				},
				BProductLine: {
					icon: 'iconfont-e612',
					name: '线路',
					url: '/package/system/line/index'
				},
				BProductHotel: {
					icon: 'iconfont-e604',
					name: '酒店',
					url: '/package/hotelSystem/index'
				},
				// BusinessShare: {
				// 	icon: 'iconfont-e631',
				// 	name: '选品池',
				// 	url: ''
				// },
				BShareFlowPublish: {
					icon: 'iconfont-e620',
					name: '推广',
					url: '/package/system/share/trafficShare/index'
				},
				BProductErp: {
					icon: 'iconfont-e602',
					name: 'ERP管理',
					url: '/package/system/erp/index'
				},
				BProductLocal: {
					icon: 'iconfont-e68c',
					name: '产品管理',
					url: '/package/system/product/p-display/index'
				},
				BOrderManageProduct: {
					icon: 'iconfont-e664',
					name: '订单管理',
					url: '/package/orderSystem/business/product/index?type=1'
				},
				BOOWOrder: {
					icon: 'iconfont-e634',
					name: '核销',
					url: '/package/system/order/verifiOrder/search'
				},
				BUserBusinessValidate: {
					icon: 'iconfont-e636',
					name: '审核',
					url: '/package/system/setting/DistributionAudit/index'
				}
			},
			initNav: [],
			navList: []
		};
	},
	computed: {
		...mapState(['vuex_adminuser']),
		percentage() {
			let num;
			num = (this.analysis.order_money / this.analysis.sum_money) * 100;
			return parseInt(num || 0);
		}
	},
	onLoad() {
		// if (this.vuex_adminuser.pk_id) {
		uni.setNavigationBarTitle({
			title: this.vuex_business.name
		});
		this.$loading();
		adminPost('GetRealAnalysis', {
			pk_id: this.vuex_adminuser.pk_id
		}).then(res => {
			this.isLogin = true;
			this.$hide();
			this.analysis = res.data;
		});
		// } else {
		// 	getParamsLogin();
		// }
	},
	onShow() {
		let params = {
			pk_id: this.vuex_adminuser.optionId,
			content: Object.keys(this.navObj).join(','),
			type: this.vuex_adminuser.port_type
		};
		this.$resPost('GetNavigationList', params)
			.then(({ data }) => {
				let list = [
					{
						icon: 'iconfont-e617',
						name: '业绩汇总',
						url: '/package/system/shareholder/index'
					}
				]
				let newList = data.map(item => {
					return this.navObj[item.name];
				});
				list = list.concat(newList)
				list = list.concat([
					{
						icon: 'iconfont-e749',
						name: '扫一扫',
						url: 'scan'
					},
					{
						icon: 'iconfont-e609',
						name: '退出登录',
						url: 'logout'
					}
				]);
				this.navList = this.initNav.concat(list);
			})
			.catch(() => {
				this.navList = [
					{
						icon: 'iconfont-e609',
						name: '退出登录',
						url: 'logout'
					}
				];
			});
	},
	methods: {
		open() {
			this.$linkTo('/package/system/setting/index');
		},
		openItem(url, idx) {
			if (url == 'scan') {
				wxScanCode({ onlyFromCamera: true }).then(res => {
					if (res.result) {
						this.jumpPath(res.result);
					}
				});
			} else if (url == 'logout') {
				this.$u.vuex('vuex_adminuser', {});
				this.$linkTo('/package/system/login', 'redirectTo');
			} else {
				this.$linkTo(url);
			}
		},
		jumpPath(str) {
			let obj = JSON.parse(str)
			if (obj && obj.url) {
				console.log('url',obj)
				if(obj.query && obj.query.business == this.vuex_business.pk_id){
					let path = obj.url + queryParams(obj.query)
					this.$linkTo(path);
				}
				return
				let arr = str.split('?');
				if (arr[1]) {
					let queryArr = arr[1].split('&');
					let findBus = queryArr.some(item => {
						let itemArr = item.split('=');
						if (itemArr[0] == 'business' && itemArr[1] == this.vuex_business.pk_id) {
							return true;
						} else {
							return false;
						}
					});
					if (findBus) {
						// 确定是当前小程序的合法 约定的二维码
						this.$linkTo(str);
					}
				}
			}
		}
	}
};
</script>
<style>
page {
	background-color: #f5f5f5;
}
</style>
<style lang="scss" scoped>
.home {
	padding: 20rpx 0;

	.pb-20 {
		padding-bottom: 20rpx;
	}

	.mr-20 {
		margin-right: 20rpx;
	}

	.mb-4 {
		margin-bottom: 4rpx;
	}

	.banner {
		position: relative;
		margin: 0 30rpx 20rpx;

		.setting {
			position: absolute;
			right: 30rpx;
			top: 20rpx;
		}

		.banner-title {
			display: flex;
			position: absolute;
			left: 78rpx;
			top: 34rpx;
			align-items: center;

			.av-img {
				width: 110rpx;
				height: 110rpx;
				border-radius: 50%;
				overflow: hidden;
			}

			.tit {
				display: flex;
				flex-direction: column;
				margin-left: 20rpx;
				color: #fff;
			}
		}
	}

	.transaction {
		width: 696rpx;
		margin: 0 auto 20rpx;
		background-color: #fff;
		padding: 30rpx;
		position: relative;
		border-radius: 20rpx;

		.transaction-title {
			font-size: 34rpx;
			font-weight: bold;
			color: #333;
		}

		.echart {
			text-align: center;
			position: relative;
			padding-top: 46rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			.progress_box {
				position: relative;

				.xian_box {
					position: absolute;
					top: 44rpx;
					left: 44rpx;
					right: 44rpx;
					height: 50%;
					background-size: 100%;
					background-repeat: no-repeat;
				}

				.echart-title {
					display: flex;
					flex-direction: column;
					align-items: center;
					position: absolute;
					top: 100rpx;
					left: 50%;
					transform: translateX(-50%);
				}
			}
		}

		.num_box {
			display: flex;
			flex-direction: column;
			align-items: center;
			position: absolute;
			bottom: 60rpx;

			&.num-left {
				left: 60rpx;
			}

			&.num-right {
				right: 60rpx;
			}
		}
	}

	.nav {
		width: 696rpx;
		margin: 0 auto;
		background-color: #fff;
		padding: 36rpx 25rpx;
		display: flex;
		border-radius: 20rpx;
		flex-wrap: wrap;
		justify-content: space-between;

		.nav-item {
			display: flex;
			// flex: 1;
			width: 25%;
			margin-bottom: 20rpx;
			flex-direction: column;
			align-items: center;

			.img {
				height: 80rpx;
				width: 80rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 50%;
				background-color: #f2f9ff;
				margin-bottom: 20rpx;
				color: #3297ef;
			}
		}
	}
}
</style>
